package com.bjsxt.userCenter.common.util;

import org.springframework.stereotype.Component;

@Component("page")
public class PageUtil
{	
	/*当前页第一条记录条数*/
	private int currRecord;
	/*每页显示多少条数据*/
	private int size = 10;
	/*总记录数*/
	private int totalRecord;
	/*当前页*/
	private int currPage;
	/*上一页*/
	private int parPage;
	/*下一页*/
	private int nextPage;
	/*总页数*/
	private int totalPage;
	
	public PageUtil()
	{
	}

	public int getSize()
	{
		return size;
	}

	public void setSize(int size)
	{
		this.size = size;
	}

	public int getTotalRecord()
	{
		return totalRecord;
	}
	
	public void setTotalRecord(int totalRecord)
	{
		this.totalRecord = totalRecord;
		this.getTotalPage();
		this.getCurrPage();
	}

	public int getTotalPage()
	{
		this.totalPage=(int)(Math.ceil(this.totalRecord*1.0/this.size));
		return this.totalPage;
	}

	public int getCurrPage()
	{
		/*if(this.currPage<1)
		{
			this.currPage = 1;
		}
		if(this.currPage>this.getTotalPage()&&this.totalRecord>0)
		{
			this.currPage = this.getTotalPage();
		}
		return this.currPage;*/
		if(this.getTotalRecord()>0)
		{
			if(this.currPage<1)
			{
				this.currPage = 1;
			}
			if(this.currPage>this.getTotalPage())
			{
				this.currPage = this.getTotalPage();
			}
		}else
		{
			this.currPage = 0;
		}
		return this.currPage;
	}

	public void setCurrPage(int currPage)
	{
		this.currPage = currPage;
	}

	public int getCurrRecord()
	{	
		
		this.currRecord = (this.currPage-1)*this.size;
		return currRecord;
	}

	public int getParPage()
	{
		if(this.currPage>1)
		{
			this.parPage = this.currPage - 1;
			return this.parPage;
		}
		this.parPage = this.currPage;
		return this.parPage;
	}

	public int getNextPage()
	{
		if(this.getCurrPage()<this.getTotalPage()&&this.totalRecord>0)
		{
			this.nextPage = this.currPage + 1;
			return this.nextPage;
		}
		this.nextPage = this.totalPage;
		return this.nextPage;
	}

	

	@Override
	public String toString()
	{
		return "PageUtil [currRecord=" + this.getCurrRecord() + ", size=" + this.getSize() + ", totalRecord=" + this.totalRecord + ", currPage="
				+ this.getCurrPage() + ", parPage=" + this.getParPage() + ", nextPage=" + this.getNextPage() + ", totalPage=" + this.getTotalPage() + "]";
	}
	
	
	
	
}
